package com.youhong.teethcare.adapter;

import android.content.res.Resources;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.youhong.teethcare.R;
import com.youhong.teethcare.utils.Util;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PointAdapter extends RecyclerView.Adapter {



    List<String> contactList;
    int level;
    int score;
    public PointAdapter(List<String> contactList,int level,int score) {
        this.contactList = contactList;
        this.level=level;
        this.score=score;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new PointViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_points, parent, false));
    }


    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        PointViewHolder pointViewHolder = (PointViewHolder) holder;
        Resources resources=holder.itemView.getContext().getResources();
        String pointLabel=resources.getString(R.string.strings127);
        String score=position+1==level?this.score+"":contactList.get(position);
        pointViewHolder.view3.setVisibility((position==0||position==2)?View.VISIBLE:View.GONE);
        pointViewHolder.view4.setVisibility((position==3||position==4)?View.VISIBLE:View.GONE);
        if(position==2) pointViewHolder.view4.setVisibility(View.INVISIBLE);


        int[]selectedList= Util.getResourcesImageArray(holder.itemView.getContext(),R.array.level_selected);
        pointViewHolder.ivPoint.setImageResource(selectedList[position]);
        pointViewHolder.tvPoints.setText(score+pointLabel);
    }
    public void setLevel(int level){
        this.level=level;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return contactList.size();
    }

    static class PointViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_Point)
        ImageView ivPoint;
        @BindView(R.id.tvPoints)
        TextView tvPoints;
        @BindView(R.id.view3)
        RelativeLayout view3;
        @BindView(R.id.view4)
        RelativeLayout view4;
        public PointViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
